<?php
/**
 * 取消关注
 */
require_once dirname(dirname(__DIR__))."/common.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\model\UserFollow;
//实例化数据库
$db =  SysResource::getDB(true);
$UserFollow = new UserFollow($db);
$UserFollow->setDb($db);
//实例化redis
$redis = SysResource::getRedis();
//这里有5个队列,所以循环5次
for($i=1;$i<=5;$i++){
    //每个队列再去循环100次取数据
    for($j=1;$j<=100;$j++){
//        $key = REDIS_PREFIX."follow_del_".$i;
        $key = REDIS_PREFIX."test_follow_del_".$i;
        //从队列中弹出一个值
        $res=$redis->rPop($key);
        //把对象变为数组
        $data=json_decode($res,true);
        if(!empty($data)){
            //加入数据库
            $res=$db->delete("material_follow",['my_uuid'=>$data['my_uuid'],'other_uuid'=>$data['other_uuid']]);
            //添加失败再去重新入队列
            if(!$res){
                if($i==1){
//                    $key = REDIS_PREFIX."follow_5";
                    $key = REDIS_PREFIX."test_follow_5";
                    $redis->lPush($key,json_encode($data));
                }else if($i==2){
//                    $key = REDIS_PREFIX."follow_1";
                    $key = REDIS_PREFIX."test_follow_1";
                    $redis->lPush($key,json_encode($data));
                }else if($i==3){
//                    $key = REDIS_PREFIX."follow_2";
                    $key = REDIS_PREFIX."test_follow_2";
                    $redis->lPush($key,json_encode($data));
                }else if($i==4){
//                    $key = REDIS_PREFIX."follow_3";
                    $key = REDIS_PREFIX."test_follow_3";
                    $redis->lPush($key,json_encode($data));
                }else if($i==5){
//                    $key = REDIS_PREFIX."follow_4";
                    $key = REDIS_PREFIX."test_follow_4";
                    $redis->lPush($key,json_encode($data));
                }
            }
        }else{
            continue;
        }

    }
}

?>